home *** CD-ROM | disk | FTP | other *** search
/ H4CK3R 14 / hacker14.iso / programacao / visual / perl.exe / {app} / Webroot / cgi-bin / time4.pl < prev    next >
Encoding:
Perl Script  |  2003-01-11  |  1.2 KB  |  48 lines

  1. #!perl
  2.  
  3. use CGI ':standard';
  4.  
  5. use POSIX 'strftime';
  6.  
  7. # print the HTTP header and the HTML document
  8. print header,
  9.     start_html('A Virtual Clock'),
  10.     h1('A Virtual Clock');
  11. print_time();
  12. print_form();
  13. print end_html;
  14.  
  15. # print out the time
  16. sub print_time {
  17.     my($format);
  18.     if (param) {
  19.         $format = (param('type') eq '12-hour') ? '%r ' : '%T ' if param('time');
  20.         $format .= '%d ' if param('day');
  21.         $format .= '%B ' if param('month');
  22.         $format .= '%A ' if param('day-of-month');
  23.         $format .= '%Y ' if param('year');
  24.     } else {
  25.         $format = '%r %A %B %d %Y';
  26.     }
  27.     $current_time = strftime($format,localtime);
  28.     print "The current time is ",strong($current_time),".",hr;
  29. }
  30.  
  31. # print the clock settings form
  32. sub print_form {
  33.     print start_form,
  34.     "Show: ",
  35.     checkbox(-name=>'time',-checked=>1),
  36.     checkbox(-name=>'day',-checked=>1),
  37.     checkbox(-name=>'month',-checked=>1),
  38.     checkbox(-name=>'day-of-month',-checked=>1),
  39.     checkbox(-name=>'year',-checked=>1),
  40.     p(),
  41.     "Time style: ",
  42.     radio_group(-name=>'type',
  43.                 -values=>['12-hour','24-hour']),
  44.     p(),
  45.     reset(-name=>'Reset'),
  46.     submit(-name=>'Set'),
  47.     end_form;
  48. }